﻿using DefCore.Mapping;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DefCore.Core.QueryContexts
{
    public sealed class CellQueryContext
    {
        protected CellQueryContext()
        {

        }
        
        //Methods
        public List<KeyValuePair<CompassDirection, CellBase>> GetNeighboughs(CellBase cell)
        {
            List<KeyValuePair<CompassDirection, CellBase>> collection = new List<KeyValuePair<CompassDirection, CellBase>>();

            int count = 0;
            foreach (Point p in Globals.Directions)
            {
                Point newMap = new Point(cell.MapPosition.MapPosition.X + p.X, cell.MapPosition.MapPosition.Y + p.Y);

                if (Objects.LevelInstance.GameCellMap.Exists(newMap.X, newMap.Y))
                    collection.Add(new KeyValuePair<CompassDirection, CellBase>((CompassDirection)count, Objects.LevelInstance.GameCellMap[newMap.X, newMap.Y]));
                else
                    collection.Add(new KeyValuePair<CompassDirection, CellBase>((CompassDirection)count, null));

                count++;
            }

            return collection;
        }
        public CellBase GetNeighbough(CellBase cell, CompassDirection cDirection)
        {
            KeyValuePair<CompassDirection, CellBase> b = GetNeighboughs(cell).Where(x => x.Key == cDirection).Single();
            return b.Value;
        }
        
        public static CellQueryContext Create() { return new CellQueryContext(); }
    }
}
